package com.cizzy.comment.controller;

import com.cizzy.comment.common.Result;
import com.cizzy.comment.entity.dao.CommentDAO;
import com.cizzy.comment.entity.dto.CommentDTO;
import com.cizzy.comment.entity.vo.CommentRequest;
import com.cizzy.comment.service.ICommentService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author terry
 * @since 2023-11-04
 */
@Controller
@CrossOrigin
@RequestMapping("/comment/")
public class CommentController {

    @Resource
    private ICommentService commentService;

    @Resource
    private LoadBalancerClient loadBalancerClient;

//    @Resource
//    private UserFeign userFeign;

//    @Autowired
//    private RestTemplate template;

//    @Resource
//    private RedissonClient redissonClient;

    @ResponseBody
    @PostMapping("addComment")
    public Result<CommentDAO> addComment(@RequestBody CommentDTO commentDTO) {
        CommentDAO comment = new CommentDAO();
        comment.convertFromCommentDTO(commentDTO);
        // TODO 加分布式锁
        commentService.createComment(comment);
        return Result.success(comment);
    }

    @ResponseBody
    @GetMapping("getCommentListByVideoId")
    public Result<List<CommentDTO>> getCommentListByVideoId(@RequestBody CommentRequest commentRequest) {
        return commentService.getCommentListByVideoId(commentRequest);
    }

    @ResponseBody
    @GetMapping("getBulletChatCommentList")
    public Result<List<CommentDTO>> getBulletChatCommentList(@RequestBody CommentRequest commentRequest) {
        return commentService.getBulletChatCommentList(commentRequest);
    }

    @ResponseBody
    @GetMapping("getCommentPageByVideoId")
    public Result<List<CommentDTO>> getCommentPageByVideoId(@RequestBody CommentRequest commentRequest) {
        return commentService.getCommentPageByVideoId(commentRequest);
    }

    @ResponseBody
    @GetMapping("getCommentListByParentCommentId")
    public Result<List<CommentDTO>> getCommentListByParentCommentId(@RequestBody CommentRequest commentRequest) {
        return commentService.getCommentListByParentCommentId(commentRequest);
    }

    @ResponseBody
    @GetMapping("getCommentPageByParentCommentId")
    public Result<List<CommentDTO>> getCommentPageByParentCommentId(@RequestBody CommentRequest commentRequest) {
        return commentService.getCommentPageByParentCommentId(commentRequest);
    }
}
